from django.contrib.auth.models import AbstractUser
from django.db import models


class Clazz(models.Model):
    """班级模型"""
    name = models.CharField(db_comment="班级名", max_length=50)

    manage = models.CharField(db_comment="班主任", max_length=30)

    duration = models.IntegerField(db_comment="课程时长")

    status = models.BooleanField(db_comment="状态 0 毕业 1 正常", null=True, blank=True, default=True)

    create_time = models.DateTimeField(db_comment="录入时间", auto_now_add=True, null=True, blank=True)

    update_time = models.DateTimeField(db_comment="修改时间", auto_now=True, null=True, blank=True)

    delete = models.BooleanField(db_comment="删除标记", db_default=False, db_column="is_delete", blank=True)

    class Meta:
        db_table = 'tb_clazz'


class User(AbstractUser):
    # 配置一个班级 关系属性 (一对多)
    clazz = models.ForeignKey(to=Clazz, on_delete=models.RESTRICT, db_column="clazz_id", blank=True, null=True,
                              related_name="users")

    name = models.CharField(db_comment="真实姓名", max_length=10, blank=True, null=True)

    class Meta:
        swappable = "AUTH_USER_MODEL"
        db_table = "auth_user"
